<?php
class MallAction extends BaseAction
{
    public function index()
    {
    }

    /**
     * 获取单个商场信息
     * id,name,initial,pic_url,intr
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function item()
    {
        $allFilelds = 'id,name,initial,pic_url';
        $filelds = $this->getFields();
        //获取字段处理
        if ($filelds == '*') {
            $filelds = 'id, name, initial';
        } else {
            $healthy = array("pic_url");
            $yummy = array("image");
            $filelds = str_replace($healthy, $yummy, $filelds);
        }
        $id = $this->_get('id', 'intval');
        $initial = $this->_get('initial');
        //获取
        $map = array();
        if (!empty($id)) {
            $map['id'] = $id;
        }
        if (!empty($initial)) {
            $map['initial'] = $initial;
        }
        $MallModel = M('Market');
        if (!empty($id) || !empty($initial)) {
            $mall = $MallModel->where($map)->field($filelds)->find();
            if (count(explode('image', $filelds)) > 1) {
                $MarketModel = D('Market');
                $mall['pic_url'] = $MarketModel->getMarketImage($mall['image']);
                unset($mall['image']);
            }
            if (!empty($mall)) {
                $mid = $mall['id'];
                //$attrCount = D('MarketAttention')->findAttCount($mid);
                $brandCount = D('FloorBrand')->getMallBrandCount($mid);
                $brandNewCount = D('BrandNews')->getMallNewCount($mid);
                // $mall['att_count'] = $attrCount;
                $mall['brand_count'] = $brandCount;
                $mall['brand_new_count'] = $brandNewCount;
            }
            if (empty($mall)) {
                $this->dataReturn('找不到对应商场信息', 0, 0);
            } else {
                $this->dataReturn($mall, 0, 1);
            }
        }
    }

    /**
     * 获取商场列表
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function items()
    {
        $allFilelds = 'id,name,initial,pic_url,intr';
        //获取
        $map = array();
        $cbd = $this->_get('bus', 'intval');
        $filelds = $this->getFields();
        //获取字段处理
        if ($filelds == '*') {
            $filelds = 'id, name, initial';
        } else {
            $healthy = array("pic_url");
            $yummy = array("image");
            $filelds = str_replace($healthy, $yummy, $filelds);
        }
        $order = '';
        if (empty($cbd)) {
            //没有选择商圈LBS距离排序
            //如果没有LBS 就按照关注度
            $order = 'att_count';
        } else {
            $order = 'att_count';
            $map['cbd'] = $cbd;
        }
        $MarketModel = D('Market');
        $malls = $MarketModel->field($filelds)->where($map)->order($order)->select();
        //遍历商场数据
        if (empty($malls)) {
            $this->dataReturn('找不到对应商场信息', 0, 0);
        } else {
            foreach ($malls as $key => $mall) {
                if (count(explode('image', $filelds)) > 1) {
                    $malls[$key]['pic_url'] = $MarketModel->getMarketImage($mall['image']);
                    unset($malls[$key]['image']); //去除不需要的返回值
                }
            }
            $this->dataReturn($malls, 0, 1);
        }
    }
}

?>